import { request } from '@/apis';
import { addPrefix } from '@/utils/helper';

const prefixUrl = '/ep-query';

const Api = {
  /** 热门搜索 */
  hotCompany: '/hotCompany',
  search: '/search'
};

const UserCenterApi = {
  getGroupListAndCompanyId: '/user-center/monitors/getGroupListAndCompanyId',
  addMember: (groupId: number) => `/user-center/monitors/detail/addCompany?groupId=${groupId}`
};

addPrefix(Api, prefixUrl);

/** 获取热门搜索 */
export const getHotCompany = () =>
  request.get(
    { url: Api.hotCompany },
    {
      ignoreCancelToken: false
    }
  );

/** 获取搜索结果 */
export interface ISearchParams {
  wd: string | number;
  limit: number;
  offset: number;
}

export const searchCompany = (params: ISearchParams) => request.get({ url: Api.search, params });

export const getGroupListAndCompanyId = () => request.get({ url: UserCenterApi.getGroupListAndCompanyId, params: { limit: 9999, offset: 0 } });

export const addMember = (groupId: number, params: string[]) => request.post({ url: UserCenterApi.addMember(groupId), params }, { isTransformResponse: false });
